﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XCI.Sys.Service;
using XCI.Extensions;
using XCI.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Sys.Forms
{
    public partial class FrmRevisePassword : FrmBase
    {
        private readonly string _userIds;

        public FrmRevisePassword(string userIds)
        {
            InitializeComponent();
            _userIds = userIds;
        }

        private void FrmRevisePassword_Load(object sender, EventArgs e)
        {
            editPassword.Focus();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string password = editPassword.Text;
            string confirmPassword = editConfirmPassword.Text;
            if (_userIds.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请先选择需要重置的用户");
                return;
            }

            if (password.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请输入新密码");
                editPassword.Select();
                return;
            }

            if (!password.Equals(confirmPassword))
            {
                MessageBoxHelper.ShowWarn("确认密码必须与新密码输入一致");
                editConfirmPassword.Select();
                return;
            }

            var result = UserService.Instance.RevisePassword(_userIds, password);
            if (result)
            {
                MessageBoxHelper.ShowMessage("用户密码重置成功");
                ResultOk();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            ResultCancel();
        }
    }
}